/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package helpdesk;

import java.util.UUID;
import com.mongodb.BasicDBObject;
import com.mongodb.DBObject;
import java.util.Iterator;
import java.util.Set;

/**
 *
 * @author eversojk
 */
public class Announcement {
    
    // attributes
    public String author;
    public String title;
    public String body;
    public String announceId;
    
    Announcement (String author, String title, String body)
    {
        this.author = author;
        this.title = title;
        this.body = body;
        this.announceId = UUID.randomUUID().toString();
    }
    
    Announcement (String author, String title, String body, String announceId)
    {
        this.author = author;
        this.title = title;
        this.body = body;
        this.announceId = announceId;
    }
    
    // easily converts an announcement object to db object to store
    public BasicDBObject toBasicDBOBject()
    {
        BasicDBObject result = new BasicDBObject();
        
        result.put("author", this.author);
        result.put("title", this.title);
        result.put("body", this.body);
        result.put("announceId", this.announceId);
        
        return result;
    }
    
    // converts a db object into an announcement
    public static Announcement fromDBObject(DBObject a)
    {
        String author = a.get("author").toString();
        String title = a.get("title").toString();
        String body = a.get("body").toString();
        String announceId = a.get("announceId").toString();
        
        Announcement announcement = new Announcement(author, title, body, announceId);
        
        return announcement;        
    }
}
